package html.note8_7;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class HtmlTag {

	public static void main(String[] args) {
		Document document;
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		try {
			// document = Jsoup.parse(new File("src/html/note8_7/bdqn.html"),
			// "UTF-8");
			document = Jsoup.connect("http://www.baidu.com/").get();
			Element eheader = document.head();
			Elements eles = eheader.getAllElements();
			for (Element e : eles) {
				if (map.containsKey(e.tagName())) {
					map.put(e.tagName(), map.get(e.tagName()) + 1);
				} else {
					map.put(e.tagName(), 1);
				}
			}
			System.out.println();
			Element ebody = document.body();
			eles = ebody.getAllElements();
			for (Element e : eles) {
				if (map.containsKey(e.tagName())) {
					map.put(e.tagName(), map.get(e.tagName()) + 1);
				} else {
					map.put(e.tagName(), 1);
				}
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Set<String> keys = map.keySet();
		Iterator<String> iter = keys.iterator();
		while (iter.hasNext()) {
			String key = iter.next();
			System.out.println(key + "\t" + map.get(key) + "次");

		}
		// System.out.println(map.toString());
	}
}
